#coding:utf-8

#队列优先级
PRI_NORMAL = 5
PRI_URGENT = 0

class Form(object):
    Columns = (('网站', 40), ('名称',100), ('总价', 60), 
               ('单价', 60), ('运费', 40), (r'成交量/评论数',60), 
               ('链接', 40), ('商家', 40), ('时间', 100))
    
    def __init__(self):
        self.name = ""
        self.price = 0
        self.model = ""
        self.description = ""
        self.resultList = {}
        self.agentIds = []
        self.pri = PRI_NORMAL

    def ShowNewResult(self,result):
        print "网站：",result.site
        print "商家：",result.store
        print "名称：",result.name
        print "链接：",result.link
        print "价格：",result.price
        print "运费：",result.carriage
        print "时间：",result.time
        print "成交量：",result.volume
        
    def AddResult(self, site, result):
        if site not in self.resultList:
            self.resultList[site] = []
            
        result.totalprice = result.price + result.carriage
            
        for re in self.resultList[site]:
            if re.site == result.site and re.store == result.store and re.name == result.name:                
                if re.totalprice < result.totalprice:
                    re.totalprice = result.totalprice
                    re.price = result.price
                    re.carriage = result.carriage
                    re.link = result.link
                    re.volume = result.volume
                    re.time = result.time
                    self.ShowNewResult(re)
                return
        self.resultList[site].append(result)
        self.ShowNewResult(result)
